package com.wyh.controller;


import com.wyh.common.annotation.Log;
import com.wyh.common.annotation.RateLimiter;
import com.wyh.common.enums.BusinessType;
import com.wyh.common.response.PageInfo;
import com.wyh.common.result.R;
import com.wyh.common.util.ExcelUtils;
import com.wyh.entity.AdminManager;
import com.wyh.request.AdminManagerRequest;
import com.wyh.service.IAdminManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 直播间管理员控制层
 *
 * @author WangYuHang
 * @date 2024-03-03
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "直播间管理员接口管理",tags = "直播间管理员接口管理")
@RequestMapping("/admin/adminManager" )
public class AdminManagerController {

    private final IAdminManagerService iAdminManagerService;

    /**
     * 分页查询直播间管理员列表
     */
    @ApiOperation(value = "分页查询直播间管理员列表")
    @PostMapping("/pageList")
    public R<PageInfo<AdminManager>> pageList(@RequestBody AdminManagerRequest adminManagerRequest) {
        return R.success(iAdminManagerService.pageList(adminManagerRequest));
    }

    /**
     * 获取直播间管理员详细信息
     */
    @ApiOperation(value = "获取直播间管理员详细信息")
    @GetMapping(value = "/query/{id}")
    public R<AdminManager> detail(@PathVariable("id") Integer id) {
        return R.success(iAdminManagerService.getById(id));
    }

    /**
     * 新增直播间管理员
     */
    @Log(title = "新增直播间管理员", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增直播间管理员")
    @PostMapping("/add")
    public R<Void> add(@RequestBody AdminManagerRequest adminManagerRequest) {
        iAdminManagerService.add(adminManagerRequest);
        return R.success();
    }

    /**
     * 修改直播间管理员
     */
    @Log(title = "修改直播间管理员", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改直播间管理员")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody AdminManagerRequest adminManagerRequest) {
        iAdminManagerService.update(adminManagerRequest);
        return R.success();
    }

    /**
     * 删除直播间管理员
     */
    @Log(title = "删除直播间管理员", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除直播间管理员")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Integer[] ids) {
        iAdminManagerService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出直播间管理员
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody AdminManagerRequest adminManagerRequest) throws IOException {
        List<AdminManager> list = iAdminManagerService.list(adminManagerRequest);
        ExcelUtils.exportExcel(list, AdminManager.class, "直播间管理员信息", response);
    }
}
